var _eiinfo;
var _regions = new Array()
_regions[0] = "ef_region_result";
_regions[1] = "ef_region_detail";
 
efform_onload = function() {
	_eiinfo = new _getEi();
	$('#ef_region_detail').hide();
	hideAndShowSubButtons(false);
	queryMain();
}; 
/**
 * 查询
 */
function queryMain() {
	efgrid.submitInqu("ef_grid_result", "ZM", "ZMCC20", "query");
}

/**
 * 按钮显示/隐藏
 */
var hideAndShowSubButtons = function(status) {
	if (!status) {
		efbutton.setButtonStatus("confirm", false);
		efbutton.setButtonStatus("cancel", false);
	} else {
		efbutton.setButtonStatus("confirm", true);
		efbutton.setButtonStatus("cancel", true);
	}
}

/**
 * 反馈
 */
button_feedback_onclick = function() {
	var grid = efgrid.getGridObject("ef_grid_result");
	var rows = grid.getCheckedRows();
	var rowLength = rows.length;
	if (rowLength != 1) {
		EFAlert("请选择一条生产问题！");
		return;
	}

	var fdRecordId = grid.getCellValue(rows[0], 0, TYPE_DATA, true);
	var fdRecordHandleId = grid.getCellValue(rows[0], 1, TYPE_DATA, true);

	var eiinfo = new EiInfo();
	eiinfo.set("fdRecordId", fdRecordId);
	eiinfo.set("fdRecordHandleId", fdRecordHandleId);

	var ajax_callback = efform.getSystemAjaxCallback("ef_region_detail");
	EiCommunicator.send("ZMCC20", "getDetailOfProblem", eiinfo, ajax_callback);

	// 隐藏/显示相关region
	hideAllRegions(_regions);
	$('#ef_region_detail').show();
	hideAndShowSubButtons(true);
}

/**
 * 反馈后确定
 */
button_confirm_onclick = function() {

	var isCheck = check();
  	if (isCheck == 0) {
        return;
    }
  	
	if (efvalidateDiv("ef_region_detail")) {
		var info = getDetail("ef_region_detail", "detail");
		if (null != info) {
			EiCommunicator.send("ZMCC20", "feedback", info, ajax_callback);
		}
	}
}

/**
 * 回调
 */
var ajax_callback = {
	onSuccess : function(eiInfo) {
//		window.parent.location.reload();
		hideAllRegions(_regions)
		$('#ef_region_result').show();
		queryMain();
	},
	onFail : function(eMsg) {
		EFAlert("反馈失败，原因：" + eMsg);
	}
}

/**
 * 反馈页面 关闭
 */
button_cancel_onclick = function() {
	hideAllRegions(_regions);
	$('#ef_region_result').show();
}

/**
 * tab切换
 * @param currentIndex
 * @param index
 */
function fundiv(currentIndex, index) {
	currentIndexTemp = currentIndex;
	indexTemp = index;
	if (index == 0) {

	} else if (index == 1) {
		var frame = frames[0];

		frame.src = "DispatchAction.do?efFormEname=ZMCC21";
		efform.setStatus(0, "正在加载...");
	}
}

/**
 * 整改反馈——输入项校验
 */
function check() {
	var fdFeedback = $("#detail-0-fdFeedback").val().trim(); // 整改反馈

	if (fdFeedback == "") {
		SCZXAlert("整改反馈不能为空！");
		return false;
	} else if (fdFeedback.getBytes() > 500) {
		SCZXAlert("整改反馈不能超过500个字符！");
		return false;
	}
	return true;
}

String.prototype.getBytes = function() {      
    var cArr = this.match(/[^\x00-\xff]/ig);      
    return this.length + (cArr == null ? 0 : cArr.length);   
      
}  

String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
 }